<template>
	<view class="content">
		<view class="title">
			赠送一个小礼物吧～
		</view>
		<view class="list">
			<view class="item" :class="{cur:i==curItem}" v-for="(item,i) in list" :key="i" @click="pickerGift(i)">
				<image class="gift-icon" :src="item.image" mode="aspectFill"></image>
				<view class="flex-center">
					<image class="icon" src="../../static/icon-jifen.png" mode=""></image>
					<view class="money">
						{{item.money}}
					</view>
				</view>
				<view class="btn">
					<view v-if="curItem==i" @click="reward(item)">
						赠送
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "n-gift",
		data() {
			return {
				list: [],
				curItem: 0,
			};
		},
		mounted() {
			this.getGiftList()
		},
		methods: {
			// 获取礼物列表
			getGiftList() {
				this.$api.giftList().then(res => {
					if (res.code == 1) {
						this.list = res.data
					} else {
						this.$tools.toast(res.msg)
					}
				})
			},
			// 选择礼物
			pickerGift(id) {
				this.curItem = id
			},
			// 赠送礼物 支付方式1=积分2=现金
			reward(item) {
				this.$emit('click', item)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 40upx 30upx 60upx;

		.title {
			color: #519D76;
			margin-left: 20upx;
		}

		.list {
			.cur.item {
				background: rgba(81, 157, 118, .1);

				.btn {
					background: #519D76;
				}
			}

			@include menu-list(5);
			flex-wrap: wrap;
			margin-top: 38upx;

			.item {
				width: 138upx;
				height: 192upx;
				border-radius: 8upx;
				text-align: center;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 18upx;

				.gift-icon {
					width: 100upx;
					height: 100upx;
					line-height: 1;
					margin-top: 6upx;
				}

				.icon {
					width: 30upx;
					height: 30upx;
				}

				.money {
					font-size: 24upx;
					color: #000000;
					margin-left: 6upx;
				}

				.btn {
					font-size: 24upx;
					font-weight: 500;
					color: #FFFFFF;
					line-height: 42upx;
					height: 42upx;
					border-radius: 0px 0px 8upx 8upx;
					width: 100%;
				}
			}
		}
	}
</style>
